<script setup>
import { inject, ref } from "vue";
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
import { historyApi } from "@/services/user";
import { formatPrice } from "@/utils/formatPrice";

onLoad(() => {
  getList();
});
const formdata = ref({
  page: 1,
  limit: 20,
});
const myTracksData = ref([]);
const status = ref("more");
const getList = async () => {
  try {
    status.value = "loading";
    // 发送请求
    let res = await historyApi(formdata.value);
    if (res.code === 200) {
      let arr = [];
      arr = res.data.list;
      myTracksData.value = myTracksData.value.concat(arr);
      if (res.data.list.length < formdata.value.limit) {
        status.value = "no-more";
      } else {
        status.value = "more";
      }
      formdata.value.page++;
    }
  } catch (e) {
    uni.showToast({
      title: e.info,
      icon: "none",
    });
  }
};
//下拉触底
onReachBottom(() => {
  // 触发下拉触底时执行的操作
  getList();
});

const goGoods = (product_id) => {
  uni.navigateTo({
    url: "/pages/goods/details/index?id=" + product_id,
  });
};
</script>
<template>
  <view class="myTracks">
    <view v-show="myTracksData && myTracksData.length > 0">
      <view v-for="(item, index) in myTracksData" :key="index">
        <view class="top-text">
          <text>{{ item.date }}</text>
        </view>
        <view
          class="content-card"
          v-for="(item2, index2) in item.list"
          :key="index2"
        >
          <view
            class="content-box"
            @click.stop="goGoods(item2.product.product_id)"
          >
            <view class="content-left">
              <image :src="item2.product.image" mode="aspectFill"></image>
            </view>
            <view class="content-right">
              <text>{{ item2.product.store_name }}</text>
              <text>会员价:¥{{ formatPrice(item2.product.vip_price) }}</text>
              <text>{{ item2.create_time }}</text>
            </view>
          </view>
        </view>
      </view>
    </view>

    <view class="nodate-bt" v-if="myTracksData.length === 0">
      <image src="/static/nodate/nodate.png" mode="widthFix"></image>
    </view>

    <uni-load-more color="#c6c5c3" :status="status" />
  </view>
</template>

<style lang="scss" scoped>
@import "myTracks.scss";
</style>
